Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-date-format

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-date-format

fast date formating

  • 2.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
321
decreased by-34.49%
Maintainers
1
Weekly downloads
 
Created
Source

fast-date-format

Build Status Coverage Status NPM version Greenkeeper badge JavaScript Style Guide

fast-date-format is significantly faster than other date formatting modules.

Installation

npm install fast-date-format

Example

const DateFormat = require('fast-date-format');

const dateFormat = new DateFormat('YYYYMMDD');

dateFormat.format();
dateFormat.format(new Date());

Escaping

To escape characters in a format, surround the characters with square brackets.

const dateFormat = new DateFormat('[Month: ]MMMM');

dateFormat.format(); // Month: December

Tokens

Supported formatting tokens:

TokenExampleDescription
YYYY2018Year
YY182 Digit Year
MMMMJanuary..DecemberMonth name
MMMJan..Dec3 letter month name
MM01..12Month
M1..12Month
HH00..23Hours (24 hour time)
H0..23Hours (24 hour time)
hh01..12Hours (12 hour time)
h1..12Hours (12 hour time)
kk01..24Hours (24 hour time)
k1..24Hours (24 hour time)
Aam, pmPost or ante meridiem
ddddMonday..SundayDay name
dddMon..Sun3 letter day name
DDDD001..365Day of year
DDD1..365Day of year
DD01..31Day of month
D1..31Day of month
E1..7Day of week
m0..59Minutes
mm00..59Minutes
s0..59Seconds
ss00..59Seconds
SSS000..999Milliseconds
ZZ-02:00Offset from UTC
Z-0200Offset from UTC
x1528643900952Unix timestamp in ms

API

DateFormat(options)

Creates a new date formatter.

options

Either a date format as a string or an object with the following properties:

dateFormat

A date format as a string.

cache (optional)

Enables caching to increase formatting speed if set to true. Defaults to false.

DateFormat#format([date])

Formats the date according to the dateFormat. If no date is passed the current date is used.

DateFormat#addLocale(language, data)

Adds translations for the names of months and weekdays.

dateFormat.addLocale('en', {
  weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
})

Three letter abbreviations of the names are being generated from the months and weekdays.

DateFormat#setLocale(language)

Changes the locale of the DateFormat instace to language. Build-in languages: en & de.

dateFormat.addLocale('en')

Benchmark

The benchmark has been run with Node.js v10.16.3.

$ node benchmark/benchmark.js
moment x 268,396 ops/sec ±0.87% (88 runs sampled)
date-format x 380,505 ops/sec ±0.42% (91 runs sampled)
dateformat x 99,375 ops/sec ±0.91% (87 runs sampled)
fast-date-format x 1,116,499 ops/sec ±0.57% (86 runs sampled)
fecha x 230,543 ops/sec ±0.93% (93 runs sampled)
speed-date x 1,083,871 ops/sec ±0.65% (91 runs sampled)
date-fns x 101,370 ops/sec ±1.18% (89 runs sampled)
Fastest is fast-date-format

With activated cache option:

$ node benchmark/benchmarkCache.js
moment x 356,945 ops/sec ±0.92% (84 runs sampled)
date-format x 404,826 ops/sec ±0.63% (86 runs sampled)
dateformat x 111,103 ops/sec ±1.03% (86 runs sampled)
fast-date-format x 2,618,465 ops/sec ±0.90% (90 runs sampled)
fecha x 306,050 ops/sec ±0.51% (91 runs sampled)
speed-date x 1,950,085 ops/sec ±0.82% (86 runs sampled)
date-fns x 150,776 ops/sec ±0.47% (88 runs sampled)
Fastest is fast-date-format

License

MIT

Keywords

FAQs

Package last updated on 16 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc